Skip to content

fix(torchtitan): quick start 跟随 v0.4.0 recipe CLI + torch_npu nightly 栈 - #278

Open
Devin-DC-Huang wants to merge 2 commits into
Ascend:mainfrom
Devin-DC-Huang:feat/torchtitan-nightly-stack
Open

Devin-DC-Huang wants to merge 2 commits into
Ascend:mainfrom
Devin-DC-Huang:feat/torchtitan-nightly-stack

Conversation

@Devin-DC-Huang

Copy link
Copy Markdown
Contributor

背景

torchtitan v0.4.0 于 2026-10-28 发布,本文档(照 v0.3.0 写的)从那天起就一直红——到本 PR 为止 38 轮定时看护全失败(最后一次 run 43795414457 卡在 triton-install)。

上游 v0.4.0 把配置体系整个换掉了:config registry 删除,配置改成「一个返回 Trainer.Config 的普通 Python 函数」,CLI 只剩 --module / --config / --override / --comm-backend / --output-dir / --resume-step / --print-config;--training.steps / --comm.mode / --dump-folder 都不存在了。

三个互相独立的断点

  1. triton-ascend 的索引已死:华为云 Ascend PyPI 的 /test 通道 404(3.6.0 已挪到根索引)。而且 setup 块第二条命令(uv pip install pybind11)成功返回 0,把第一条的失败吞了,报错推迟到 triton-install 才暴露。
  2. uv pip install torchtitan 解析不出 0.4.0:上游把 attn-gym[linear,cudnn]==0.0.17 写成硬依赖,cudnn extra 要 cuda-python>=13 + nvidia-cutlass-dsl,与 CI 的 CUDA 排除约束直接冲突(实测 Because attn-gym[cudnn]==0.0.17 depends on cuda-python<0 ... unsatisfiable)。
  3. override 模块还是 v0.3.0 的 API:v0.4.0 删了 torchtitan/protocols/,rope 的私有 helper _maybe_wrap_positions 也没了 → import 就炸(ImportError: cannot import name '_maybe_wrap_positions')。

栈换成 torch_npu nightly

torchtitan v0.4.0 是对着 torch 2.15 开发的(它自己的 CI 钉 torch==2.15.0),要用到

  • torch.distributed.pipelining 的 analyze_pipeline_activation_liveness / PipelineStageInfo(上游顺带 import 的 Dist-MoE 包第一行就要它们)
  • FSDP2 的 MixedPrecisionPolicy(param_dtype_override_fn=...)

而正式发布的 torch_npu 最新只到 2.14.0(把 torch 钉在 2.14.0.*),是天花板——在那套栈上 import 链会在建模前就断,FSDP 阶段也会报 MixedPrecisionPolicy.__init__() got an unexpected keyword argument。本 PR 改用华为云 nightly 源的 torch_npu 2.15.0.dev20261116 + triton-ascend 3.6.0+dev20261112 + torch 2.15.0(aliyun cpu wheel),这三个 API 原生存在,不需要任何兼容垫片。

nightly 源是滚动窗口(现在只留最近约两周),所以版本号写死;等昇腾发 torch_npu 2.15.0 正式版后换回稳定源即可。

override 只剩 attention 一处

  • flex / varlen 后端在 NPU 上跑不起来(varlen 调 aten::_flash_attention_forward,torch_npu 没实现;flex 建 block mask 时 InductorError: SympifyError),换成带 dense block-causal 掩码的 SDPA。
  • RoPE 不再替换:上游 ComplexRoPE 的 complex64 gather 只存在于 eager 路径(aclnnIndex 没有 DT_COMPLEX64),而 v0.4.0 默认编译 rope 区域,编译路径 gather 的是 cache 的实数视图,NPU 能跑。
  • loss 不再换 plain CE:上游的 ChunkedLossWrapper 在 nightly 栈上原样可跑。

改动清单

  • sources/torchtitan/quick_start.md:改 nightly stack、v0.4.0 recipe 式 CLI、--excludes attn-gym、去掉 modelscope 段(v0.4.0 用自带 tokenizer)
  • tests/torchtitan/npu_compat.py:按 v0.4.0 API 重写的 attention-only override
  • tests/torchtitan/npu_recipe.py(新增):quick-start recipe(上游 llama3 debugmodel + 2 步 + 自带 c4_test)
  • tests/torchtitan/check_npu_overrides.py:断言 mask + metadata 契约 + 「override 不动 RoPE」
  • tests/torchtitan/test_npu_overrides.py / test_quick_start_ascend.py、workflow 注释同步

实测(hdc-stable-npu-1,CANN 9.1.0 / 910B4 ×2)

  • 文档里的安装命令逐条可用(torch 2.15.0+cpu / torch_npu 2.15.0.dev20261116 / triton-ascend 3.6.0+dev20261112)
  • 单卡 2 步、双卡 FSDP shard=2 + bf16 2 步:都 Training completed
  • torch-2.15 符号检查 / override 注册 / 等价性自检 / recipe 导入:输出与文档预期一致

上游 torchtitan v0.4.0(2026-10-28 发布)把配置体系整个换掉了:config registry
删除,配置改成「一个返回 Trainer.Config 的普通 Python 函数」,CLI 只剩
--module / --config / --override / --comm-backend / --output-dir / --resume-step
/ --print-config;--training.steps / --comm.mode / --dump-folder 都不存在了。
本文档是照 v0.3.0 写的,所以从 v0.4.0 发布那天起(38 轮定时看护全红)一路撞墙。

三个互相独立的断点:

1. triton-ascend 的索引已死:华为云 Ascend PyPI 的 /test 通道 404(3.6.0 已挪到
   根索引),且 setup 块第二条命令成功返回 0 把失败吞了,报错推迟到 triton-install
   才爆。改用 nightly 源。
2. uv pip install torchtitan 在 CI 的 CUDA 排除约束下解析不出 0.4.0:上游把
   attn-gym[linear,cudnn]==0.0.17 写成硬依赖,cudnn extra 要 cuda-python>=13 +
   nvidia-cutlass-dsl。文档加 --excludes attn-gym(上游对 attn-gym 有官方占位
   降级)。
3. override 模块还是 v0.3.0 的 API:v0.4.0 删了 torchtitan/protocols/,rope 的
   私有 helper _maybe_wrap_positions 也没了,import 就炸。

栈换成 torch 2.15.0 + torch_npu 2.15.0.dev20261116(华为云 nightly 源):
torchtitan v0.4.0 是对着 torch 2.15 开发的(要用 torch.distributed.pipelining
的 analyze_pipeline_activation_liveness / PipelineStageInfo 和 FSDP2 的
MixedPrecisionPolicy(param_dtype_override_fn=...)),而正式发布的 torch_npu 只到
2.14.0(把 torch 钉在 2.14.0.*),是天花板。nightly 栈上这三个 API 原生存在,
不需要任何兼容垫片。

override 只剩一处:上游的 flex / varlen attention 后端在 NPU 上跑不起来
(varlen 调 aten::_flash_attention_forward,torch_npu 没实现;flex 建 block mask
时 SympifyError),换成带 dense block-causal 掩码的 SDPA。RoPE 不再替换:
上游 ComplexRoPE 的 complex64 gather 只在 eager 路径存在,而 v0.4.0 默认编译
rope 区域,编译路径 gather 的是 cache 的实数视图,NPU 能跑。loss 也不再换成
plain CrossEntropyLoss —— 上游的 ChunkedLossWrapper 在 nightly 栈上原样可跑。

新增 tests/torchtitan/npu_recipe.py(quick-start recipe:上游 llama3 debugmodel
+ 2 步 + 上游自带 c4_test 数据集),override 模块按 v0.4.0 API 重写,
等价性自检改为断言 mask + metadata 契约 + 「override 不动 RoPE」。

实测(hdc-stable-npu-1,CANN 9.1.0 / 910B4 x2):文档里的安装命令、单卡与双卡
(FSDP shard=2 + bf16)训练、以及 torch-2.15 符号检查 / override 注册 / 等价性
自检 / recipe 导入逐条对上预期输出。
github-actions Bot pushed a commit that referenced this pull request Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

📖 文档预览:https://ascend.github.io/docs/pr-preview/pr-278/sources/torchtitan/

也可打开整站首页。

构建自 bdf8729d8631cc7a7a3ae78145e8130f9de2bf12。
每次推送后自动更新,PR 关闭时自动清理。

PR Ascend#278 的 CI 复跑在单卡训练那步红了(前面的安装、torch-2.15 符号检查、override
注册、等价性自检、recipe 导入全过):

    torch._inductor.exc.InductorError: AssertionError: make_fallback
    (aten.nll_loss_forward.default): a decomposition exists, we should switch to it.

根因不是 CANN 版本,是 CI 环境变量:torch/_inductor/lowering.py 的这个断言被
`bool(os.getenv("CI"))` 守着 —— GitHub Actions 设 CI=true,断言就从不升级成硬错误;
本地跑同样的栈不会触发(所以本地 9.1.0 + nightly 全绿)。

上游默认编译 loss / fused_binary_activation / rope 三个区域,而 loss 区域的图以
aten.nll_loss_forward 结尾:inductor 在 NPU 上降不了它,只能注册 fallback,正好撞上
这个断言。recipe 把 loss(连同 deepseek 的 moe_aux_loss)留在 eager —— eager 路径走
NPU 自己的 kernel,上游的 ChunkedLossWrapper 原样就能跑;其余编译区照旧开着。

实测(hdc-stable-npu-1,CANN 9.1.0 / 910B4 x2):CI=true 下 llama3 debugmodel
单卡与双卡(FSDP shard=2 + bf16)都 Training completed。
github-actions Bot pushed a commit that referenced this pull request Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant